
import sys

n = 0
pattern = []

def dfs(bit, arr): 
    global n, pattern 
    if bit>=8: 
        #print(n, k, arr)
        a = arr[:]
        a.insert(4, 1)
        pattern.append((n, tuple(a)))
        n += 1
        return
    for i in range(3): 
        arr[bit] = i
        dfs(bit+1, arr)

'''
下面这个表，是得分不为0的棋型
0 -- 空位
1 -- 己方棋子
2 -- 对方棋子
3 -- 对方棋子或者空位
'''

sc = [
    ((1, 1, 1, 1, 1, 1), 1000000), 
    ((1, 1, 1, 1, 1, 3), 100000), 
    ((3, 1, 1, 1, 1, 1), 100000), 
    ((0, 1, 1, 1, 1, 0), 10000), 
    ((0, 1, 1, 1, 0, 3), 1000), 
    ((3, 0, 1, 1, 1, 0), 1000), 
    ((0, 1, 1, 1, 1, 3), 1000), 
    ((3, 1, 1, 1, 1, 0), 1000), 
    ((0, 1, 1, 0, 3, 3), 100), 
    ((3, 0, 1, 1, 0, 3), 100), 
    ((3, 3, 0, 1, 1, 0), 100), 
    ((3, 3, 1, 1, 1, 0), 100), 
    ((3, 0, 1, 1, 1, 3), 100), 
    ((0, 1, 0, 3, 3, 3), 10), 
    ((3, 0, 1, 0, 3, 3), 10), 
    ((3, 3, 0, 1, 0, 3), 10), 
    ((3, 3, 3, 0, 1, 0), 10), 
    ((3, 1, 1, 0, 3, 3), 10), 
    ((3, 3, 1, 1, 0, 3), 10), 
    ((3, 3, 3, 1, 1, 0), 10), 
    ((0, 1, 1, 3, 3, 3), 10), 
    ((3, 0, 1, 1, 3, 3), 10), 
    ((3, 3, 0, 1, 1, 3), 10), 
]

def match(pp): 
    for s in sc: 
        not_found = False
        for i in range(6): 
            #print(s[0], ' -- ',  pp)
            if s[0][i]!=3 and s[0][i]!=pp[i]: 
                not_found = True
                break
        if not not_found: 
            return s[1], s[0]
    return 0, None

def get_score(p): 
    ret = 0
    rp = None
    for i in range(4): 
        #print('get_score:', i, p, p[i:i+6])
        pp = p[i:i+6]
        r, kk = match(pp)
        if ret<r: 
            ret = r 
            rp = kk
    return ret, rp 

def gen_score(): 
    print('var g_score = [')
    i = 0
    for p in pattern: 
        r, _ = get_score(p[1])
        idx, shape = p
        if i%16==0: 
            print('')
        print('%d,' % r, end='')
        i += 1
    print('];')
    print('export {g_score};')

def gen_details(): 
    i = 0
    for p in pattern: 
        print('pattern: ', p)
        r, k = get_score(p[1])
        idx, shape = p
        print('i=%4d, idx=%4d, shape=%s, r=%d, k=%s' % (i, idx, shape, r, k))
        i += 1


arr = 8*[0]
dfs(0, arr)

if len(sys.argv)>1 and sys.argv[1]=='-d': 
    gen_details()
else:
    gen_score()
